package com.world.rickcloudendpoint.demo.redis.runner;

import com.world.rickcloudendpoint.common.ThreadNameFactory;
import com.world.rickcloudendpoint.common.constant.GlobalConstants;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: jlsong
 * @date: 2022/05/31 08:42:02
 * @version: 1.0
 */
@Log4j2
@Component
@Order(2)
public class ConsumerRunner implements CommandLineRunner {
    @Resource
    RedisTemplate<String, Object> redisTemplate;

//    ExecutorService pool = new ThreadPoolExecutor(8, 24, 1000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadNameFactory("Redis-Filter-Listener-"));
//ExecutorService pool =  Executors.newCachedThreadPool(new ThreadNameFactory("Redis-Filter-Listener-"));

    @Override
    public void run(String... args) throws Exception {
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.one));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.three));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.five));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.seven));
//
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.two));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.four));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.six));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.eight));
//
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.one));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.three));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.five));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.seven));
//
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.one));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.three));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.five));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.seven));
//
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.one));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.three));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.five));
//        pool.submit(() -> new RedisFilterListener(redisTemplate, GlobalConstants.RedisKeys.seven));
    }
}
